home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / timex.arc / TIMEX.C next >
Encoding:
C/C++ Source or Header  |  1985-07-04  |  2.5 KB  |  87 lines

  1. /*
  2.             Time a DOS command and display its exit code.
  3.             Portability of this program  approaches zero.
  4.             Note that the program contains functions which
  5.             are peculiar to the Lattice C library, and 
  6.             that it references locations peculiar to the 
  7.             IBM PC's memory map . Portability to workalikes is 
  8.             unknown.  Invoking the program with no arguments 
  9.             on the commandline produces a help screen.
  10.             Noncommercial distribution of source and object
  11.             code is permitted and encouraged provided that
  12.             this notice is left intact.
  13.             
  14.  
  15.                                     Ken Rice 
  16.                                     Rt #2
  17.                                     Watkinsville, GA 30677
  18.                                     July 4, 1985
  19. */
  20.  
  21. #include <stdio.h>
  22. char *malloc();
  23.  
  24. main(argc,argv)
  25.     int argc;
  26.     char **argv;
  27.     {
  28.     float ticki, tickf;            /* initial and final clock ticks */
  29.     int code;                    /* dos return code */
  30.     unsigned i = 0,buf[2];        /* holds 32-bit clock tick count */
  31.     char *nargv[32];            /* new commandline argument vector */
  32.     extern char *helptxt[];        /* the help screen */
  33.  
  34.     if (argc == 1)
  35.         help(helptxt);
  36.  
  37.     while (--argc > 0) {
  38.         if ((nargv[i] = malloc(strlen(argv[i+1]))) == NULL) {
  39.             fprintf(stderr,"timex: out of memory timing %s\n",argv[1]);
  40.             exit(1);
  41.         }
  42.         strcpy(nargv[i],argv[i+1]);
  43.         i++;
  44.     }
  45.     nargv[i] = NULL;
  46.  
  47.     peek(0x0040,0x006c,buf,4);
  48.     ticki = (0x1000 * (float)buf[1]) + (float)buf[0];
  49.  
  50.     if (forkvp(argv[1],nargv)) {
  51.         fprintf(stderr,"timex: cannot find %s for timing\n",nargv[0]);
  52.         exit(1);
  53.         }
  54.  
  55.     code = wait();
  56.     peek(0x0040,0x006c,buf,4);    
  57.     tickf = (0x1000 * (float)buf[1]) + (float)buf[0];
  58.     printf("\n%9.1fs   (%d)\n",(tickf-ticki) * 0.0549254,code);
  59.     }
  60.  
  61. /*
  62.     help module:  function and text
  63. */
  64.  
  65. help(mesg)
  66. char **mesg;
  67. {
  68.     while (*mesg != NULL)
  69.         puts(*mesg++);
  70.         exit(0);
  71. }
  72.  
  73. char *helptxt[] = {
  74. "\nDisplays the running time and exit code of a program.\n",
  75. "              Usage: timex <commandline>\n",
  76. "Where <commandline>  is any COM or EXE program in the current", 
  77. "directory or command search path and its associated arguments",
  78. "and parameters.     The timex command won't time BAT files or",
  79. "resident DOS commands (COPY, e.g.).  Run time is displayed in", 
  80. "seconds to the nearest tenth,  and the exit code is displayed",
  81. "as an eight-bit integer set off by parentheses.      Internal",
  82. "resolution of the timer is ca. 0.055 seconds.   Noncommercial",
  83. "distribution  of this  program  is  permitted  and encouraged",
  84. "provided that this notice is left intact.\n",
  85. "          Ken Rice  Rt #2  Watkinsville GA 30677",
  86. NULL };
  87.